package org.wiztools.thegreatwall;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author subwiz
 */
public class ViewUserPostServlet extends HttpServlet {

    private static final Logger LOG = Logger.getLogger(ViewUserPostServlet.class.getName());

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        LOG.info("View User Post Servlet: doGet() ");
        final String path = req.getPathInfo();
        try {
            String userName = req.getParameter("u");
            LOG.info("user name is" + userName);
            List<Post> p = new MySQLOperations().getUserPosts(userName);
            req.setAttribute("userName", userName);
            req.setAttribute("post", p);
        } catch (OperationException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
        req.getRequestDispatcher("/user.jsp").forward(req, resp);
    }
}
